refactor(community): give the provider port vendor-neutral types - #68
Merged
Conversation
The port was generic in name only. Its methods returned DiscordGuildMembership, DiscordMessage and DiscordReactionUser, and every identifier was validated against the Discord snowflake format, so the identifier regex reached callers that have no reason to know what a snowflake is. Replacing the provider would have meant editing the interface and both api_v0 services rather than swapping an adapter. The port now speaks CommunityRole, CommunityMembership, CommunityMessage, CommunityReactionUser and CommunityAccountProfile, treats identifiers as opaque strings, and drops the Discord message length limit. Discord's snowflake format, its 2000-character limit, and the global_name field it returns are refinements applied in discord/schema.ts, which is the only layer that issues those values. The provider-specific field name is mapped to displayName at the adapter boundary, matching the provider_display_name column it is stored in. Behaviour is unchanged: the adapter still rejects a malformed provider response and a guild member response for another user, both of which depend on the snowflake assertion that moved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#62 の再作成です。#61 のマージでベースブランチが削除され、GitHub が #62 を自動クローズしたため、内容そのままで develop 向けに出し直しました(#62 はレビュー済み)。
CommunityProviderは名前だけが汎用で、中身は Discord 固有でした。何が問題だったか
DiscordGuildMembership/DiscordMessage/DiscordReactionUserを返していた^\d{17,20}$)で検証され、その正規表現がアプリ層まで到達していたプロバイダを差し替えるには「アダプタを入れ替える」のではなく、インターフェースと api_v0 のサービスを書き換える必要がありました。
変更内容
ポート(中立) —
CommunityRole/CommunityMembership/CommunityMessage/CommunityReactionUser/CommunityAccountProfile。IDは不透明な文字列として扱い、メッセージ長制限も削除。アダプタ(Discord固有) —
lib/community/discord/schema.tsに snowflake 検証・2000文字制限・global_nameの写像を集約。中立スキーマを.extend()して精緻化するため検証は緩みません。挙動は不変
snowflake 検証に依存する以下のテストが移動後も通ります。
getCurrentDiscordUser rejects malformed provider responses as a bad gatewaygetGuildMembershipAPI rejects a guild member response for another user境界の確認
interface.ts/type.tsに Discord 語彙なし(コメントを除く)api_v0に Discord 固有型の参照なしDiscordSnowflakeSchemaはlib/community/discord/配下のみ🤖 Generated with Claude Code